home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_400 / 400_01 / socketpp-1.5 / test / tsockpair.cc < prev    next >
Encoding:
C/C++ Source or Header  |  1993-11-06  |  984 b   |  50 lines

  1. // tsockpair.cc. Test for -*- C++ -*- socket library
  2. // Copyright (C) 1992,1993 Gnanasekaran Swaminathan <gs4t@virginia.edu>
  3. // 
  4. // Permission is granted to use at your own risk and distribute this software
  5. // in source and binary forms provided the above copyright
  6. // notice and this paragraph are preserved on all copies.
  7. // This software is provided "as is" with no express or implied warranty.
  8. //
  9. // Version: 07Nov93 1.5
  10.  
  11. #include <pipestream.h>
  12.  
  13. main(int ac, char** av)
  14. {
  15.     iopipestream p(sockbuf::sock_dgram);
  16.  
  17.     if (p.fork()) {
  18.         // I am the Parent
  19.         p << ac << endl;
  20.         while (*av) {
  21.             p << *av++ << ' ';
  22.         }
  23.         p << endl;
  24.  
  25.         char buf[128];
  26.         p.getline(buf,127);
  27.         cout << "Parent: " << buf << endl;
  28.         return 0;
  29.     } else {
  30.         // I am the Child
  31.         int     cnt=0;
  32.         int    i;
  33.         char    buf[32];
  34.         
  35.         p >> i;
  36.         cout << "Child: " << i << ": ";
  37.         while (i--){
  38.             p >> buf;
  39.             cout << buf << ' ';
  40.             cnt++;
  41.         }
  42.         cout << endl;
  43.  
  44.         p << "Child received " << cnt << " strings\n";
  45.         return 0;
  46.     }
  47. }
  48.  
  49.     
  50.